<template>
  <div class="t-body">
    <iframe id="myIframe" :src="`${currentUrl}`" frameborder="0" style="width:100%;height: 100%;"></iframe>
  </div>
</template>

<script>
export default {
  name: "AnalysisModelCommon",
  data() {
    return {
      url: "http://10.6.172.57:8080",
      currentUrl: "",
      robotItemList: [],
    }
  },
  computed: {
    curSecondSideItem() {
      return this.$store.getters.curSecondSideItem || null
    },
  
  },
  mounted() {
    let $this = this;
    this.transMessage();
    this.currentUrl=this.url;
    window.addEventListener("message", function (event) {
      console.log(event.data);
      if (event.data.isOk) {
          $this.currentUrl = $this.url +"/#/Robot/AcquisitionControl/RealTimeCollection"
      }
    })
  },
 
  methods: {
    changeItemHandler(item) {
      this.currentUrl = this.url + item.url;
    },
    transMessage() {
      this.currentUrl = this.url.replace("/#", "");
      let token = 
          "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9naXZlbm5hbWUiOiLnrqHnkIblkZgiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZTBhMTAzZWMtNjBmMi00MDU5LWI3YWYtNjBkMGYxYjkwZGQ3IiwianRpIjoiZTBhMTAzZWMtNjBmMi00MDU5LWI3YWYtNjBkMGYxYjkwZGQ3IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9leHBpcmF0aW9uIjoiMjAyNC8xMS83IDk6MzM6MzEiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiLns7vnu5_nrqHnkIblkZgiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjoiNGFkYmNhYWQtYTllZi00MGYyLTlkMWYtODM0YTg2NGJjNzMxIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvc2lkIjoiOTk5OSIsIm5iZiI6MTczMDg1NjgxMSwiZXhwIjoxNzMwOTQzMjExLCJpc3MiOiJqY2dzIiwiYXVkIjoiamNncyJ9.3T2JsNDKbB5YTXb-RJ559uLrBZFvU5nmM8VWqIY9IRE";
      console.log("token is", token);
      setTimeout(() => {
        let iframe = document.getElementById("myIframe");
        iframe.onload = function () {
          console.log("发送");
          iframe.contentWindow.postMessage(
              {
                postMessageToken: token,
              },
              "*"
          )
        }
      }, 1000);
    },
  },
}
</script>

<style scoped lang="scss">
.t-body {
  iframe {
    height: 100%;
    width: 100%;
  }
}
</style>
